import mongoose, { Schema, Document } from "mongoose";
import { ActivityStatus } from "@/enums/ActivityStatus";

const { ObjectId } = mongoose.Types;

// 定义 Activity 接口，继承 Document 接口
export interface IActivity extends Document {
  activityId: string;
  activityName: string;
  venueId: string[];
  courtId: string[];
  userId: string[];
  startTime: number;
  endTime: number;
  status: number;
  comment: string;
  createdAt: number;
  updatedAt: number;
}

// 创建活动模式
const activitySchema = new Schema({
  activityId: {
    type: String,
    default: () => new ObjectId().toHexString(), // 自动生成活动ID
    index: true,
    unique: true,
  },
  activityName: { type: String, required: true }, // 活动名称
  venueId: { type: [String], required: true }, // 活动所在场馆的ID
  courtId: { type: [String], required: true }, // 活动所在场地的ID
  userId: { type: [String], required: true }, // 活动创建者的用户ID
  startTime: { type: Number, required: true }, // 活动开始时间戳
  endTime: { type: Number, required: true }, // 活动结束时间戳
  status: {
    type: Number,
    enum: ActivityStatus.getAllStatuses().map((ele) => ele.status),
    default: ActivityStatus.WAIT_PUBLISH.status,
  },
  createdAt: { type: Number, default: Date.now }, // 活动创建时间
  updatedAt: { type: Number, default: Date.now }, // 活动更新时间
  comment: { type: String, default: "" }, // 活动描述。备注信息
});

// 创建 ActivityModel 模型
const ActivityModel = mongoose.model<IActivity>("activities", activitySchema);

export default ActivityModel;
